/* 
 * Gneat (http://gneat.org)
 *
 * (C) Copyright 2011 and beyond - Claudio Stella, all rights reserved.
 *
 * This file is part of Gneat.
 *
 * Gneat is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (LGPL)
 * as published by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gneat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * and the GNU General Public License, for completeness, along with Gneat.  
 * If not, see <http://www.gnu.org/licenses/>.
 */
package org.neatshell.gneat.client.tool;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Strings {
	public static String join(String separator, String[] array) {
		int i = 0;
		String joint = array[i++];
		while (i < array.length)
			joint += separator + array[i++];
		return joint;
	}

	public static String join(String[] array) {
		return join(",", array);
	}

	public static String[] cleanAndSplit(String string) {
//		if (exists(s)) return trimExtra(s).split(" ");
		if (exists(string)) return string.trim().split(" ");		
		else return new String[] {};
	}

	public static String[] cleanAndSplit(String... strings) {
		List<String> list;

		if (strings != null) {
			if (strings.length > 1) {
				list = new ArrayList<String>();
				for (String string : strings) {
					list.addAll(Arrays.asList(cleanAndSplit(string)));
				}
				return (String[]) list.toArray(new String[list.size()]);
			}
			else return cleanAndSplit(strings[0]);
		} 
		else return new String[] {};
	}

	public static boolean exists(String s) {
		return s != null && !s.isEmpty();
	}

//	public static String trimExtra(String s) {
////		s = s.replaceAll("\\s+", " ");
////		if (s.startsWith(" ")) {
////			s = s.replaceFirst(" ", "");
////		}
////		return s;
//		return s.trim();
//	}
}